package com.xmy.cultivate.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xmy.cultivate.entity.AuthAdminContent;
import com.xmy.cultivate.entity.OrganizationDepartmentPrincipal;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xmy.cultivate.entity.views.LeadDataRs;
import com.xmy.cultivate.entity.views.StudentRatePay;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 部门负责人详情 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2025-05-27
 */
public interface OrganizationDepartmentPrincipalMapper extends BaseMapper<OrganizationDepartmentPrincipal> {

    @Select({"<script>",
            "SELECT",
            "GROUP_CONCAT( DISTINCT t2.year_class_id ORDER BY t2.year_class_id SEPARATOR ',' ) AS year_class_id ",
            "FROM",
            "`organization_department_principal` AS t1",
            "LEFT JOIN `org_principal_content` AS t2 ON t1.id = t2.principal_id ",
            "WHERE",
            "t1.department_id = ${departmentId} ",
            "AND t1.staff_id = ${staffId} ",
            "</script>"})
    public abstract String getPayFeeDetail(@Param("departmentId") Long departmentId, @Param("staffId") Long staffId);

    @Select({"<script>",
            "SELECT * FROM organization_department_principal",
            "WHERE",
            "department_id IN ( ${departmentId} )",
            "AND duty_id = ${dutyId} ",
            "AND staff_id = ${staffId} ",
            "AND year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND is_current = 1 ",
            "LIMIT 1",
            "</script>"})
    public abstract OrganizationDepartmentPrincipal getByDepartmentId(
            @Param("departmentId") String departmentId,
            @Param("dutyId") Long dutyId,
            @Param("staffId") Long staffId,
            @Param("yearPart") Integer yearPart,
            @Param("quarterNum") Integer quarterNum);


    @Select({"<script>",
            "SELECT",
                    "GROUP_CONCAT( DISTINCT t4.year_class_id ORDER BY t4.year_class_id ASC ) AS year_class_id ",
                    "FROM",
                    "organization_department_principal AS t1",
                    "INNER JOIN department AS t2 ON t1.department_id = t2.id",
                    "INNER JOIN org_duty AS t3 ON t1.duty_id = t3.id",
                    "INNER JOIN org_principal_content AS t4 ON t1.id = t4.principal_id ",
                    "WHERE",
                    "t1.year_part = ${yearPart}",
                    "AND t1.quarter_num = ${quarterNum}",
                    "AND t1.staff_id = ${teacherId} ",
                    "AND t3.duty_type = ${dutyType}",
            "</script>"})
    public String getYearClassIdsForTeacherId(@Param("yearPart") Integer yearPart,@Param("quarterNum") Integer quarterNum,@Param("teacherId") Long teacherId,@Param("dutyType") Integer dutyType);
}
